#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<random>
#define N 100000
using namespace std;
mt19937 RAND(random_device{}());
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int n,leng,ans,tong[N+1],length,dfn[N+1],fa[N+1],dp[N+1],ls[N+1],rs[N+1],rd[N+1];
struct reads
{
	int num,data;
	bool operator < (const reads &t)const
	{
		return data!=t.data?data<t.data:rd[num]<rd[t.num];
	}
};
bool used[N+1],vis[N+1];
vector<int>E[N+1];
priority_queue<reads>q[N+1];
void add(int x,int y)
{
	E[x].push_back(y),E[y].push_back(x);
	return;
}
bool cmp(int x,int y)
{
	return x>y;
}
void merge(int x,int y)
{
	if (q[x].size()>q[y].size()) swap(q[x],q[y]);
	while (!q[x].empty()) q[y].push(q[x].top()),q[x].pop();
	return;
}
void dfs(int x)
{
	reads d1,d2;
	while (!q[x].empty()) q[x].pop();
	dfn[x]=++leng,used[x]=1;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			fa[E[x][i]]=x,dfs(E[x][i]),merge(E[x][i],x);
	if (q[x].size()>=2) d1=q[x].top(),q[x].pop(),d2=q[x].top(),q[x].pop(),ls[x]=d1.num,rs[x]=d2.num,q[x].push((reads){x,d1.data+d2.data});
	else q[x].push((reads){x,1});
	return;
}
void dfs2(int x)
{
	vis[x]=1;
	if (ls[x]) dfs2(ls[x]);
	if (rs[x]) dfs2(rs[x]);
	return;
}
int main()
{
	freopen("bird.in","r",stdin);
	freopen("bird.out","w",stdout);
	int x,y,res;
	n=read();
	for (int i=1;i<=n-1;++i) x=read(),y=read(),add(x,y);
	for (int qt=1;qt<=500000/n;++qt)
	{
		for (int i=1;i<=n;++i) used[i]=ls[i]=rs[i]=vis[i]=0,rd[i]=i;
		shuffle(rd+1,rd+n+1,RAND);
		dfs(1),dfs2(q[1].top().num),res=(q[1].top().data<<1)-1;
		for (int i=2;i<=n;++i)
			if (vis[i]&&!vis[fa[i]])
				res=q[1].top().data<<1;
		ans=max(ans,res);
	}
	printf("%d\n",ans);
	return 0;
}
